Skip to content

Added keep alive setting - #41109

Open
craigloewen-msft wants to merge 4 commits into
masterfrom
user/crloewen/wsl-keep-alive
Open

Added keep alive setting#41109
craigloewen-msft wants to merge 4 commits into
masterfrom
user/crloewen/wsl-keep-alive

Conversation

@craigloewen-msft

@craigloewen-msft craigloewen-msft commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary of the Pull Request

Added a setting to WSL settings to keep the WSL VM alive at all times.

PR Checklist

Very simple change.
Adds a 'InstanceIdleTimeout' setting and a "WSL keep VM alive" setting to WSL settings.

Detailed Description of the Pull Request / Additional comments

Did this in WSL settings only, no major code changes.

Validation Steps Performed

Validated settings loaded correctly.

Copilot AI review requested due to automatic review settings July 17, 2026 20:00
@craigloewen-msft
craigloewen-msft requested a review from a team as a code owner July 17, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new WSL Settings UI toggle to keep the WSL VM running indefinitely by driving the existing wsl2.vmIdleTimeout setting into a negative value (which the service interprets as “do not idle-terminate”).

Changes:

  • Add a “Keep WSL VM alive” toggle to Optional Features, and disable the VM idle timeout expander when keep-alive is active.
  • Extend the Optional Features view model with keep-alive/enablement properties and related change notifications.
  • Add en-US localized strings (header/description and accessibility text) for the new setting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml Adds keep-alive toggle and disables the idle-timeout expander based on view model state.
src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs Adds computed properties for keep-alive and VM idle-timeout enablement, and updates change notification flow.
localization/strings/en-US/Resources.resw Adds localized strings for the new keep-alive setting and toggle accessibility metadata.

Comment thread src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml
Comment thread src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs Outdated
Copilot AI review requested due to automatic review settings July 27, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml:62

  • InstanceIdleTimeout is used to implement “Keep WSL VM alive” by setting a negative timeout, but this header TextBlock formats the raw value via MillisecondsStringConverter. With keep-alive enabled, this will display "-1 milliseconds" (and similarly for other negative values), which is user-unfriendly and doesn’t reflect the toggle semantics.
                <ctControls:SettingsExpander x:Name="InstanceIdleTimeoutExpander" x:Uid="Settings_InstanceIdleTimeout" IsEnabled="{x:Bind ViewModel.InstanceIdleTimeoutEnabled, Mode=OneWay}">
                    <TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.InstanceIdleTimeout, Mode=OneWay, Converter={StaticResource MillisecondsStringConverter}}"/>

Comment thread src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml.cs
Comment thread src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs
Comment thread src/windows/wslsettings/LibWsl.cs
# Conflicts:
#	localization/strings/en-US/Resources.resw
Copilot AI review requested due to automatic review settings July 27, 2026 21:46
@craigloewen-msft
craigloewen-msft enabled auto-merge (squash) July 27, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs:93

  • Toggling “Keep WSL VM alive” off always writes _defaultInstanceIdleTimeout back to InstanceIdleTimeout, which can discard a user’s previously configured distribution idle timeout (e.g., user sets 30000ms → enables keep-alive → disables keep-alive → value becomes default 15000ms). Consider preserving/restoring the last non-negative timeout value so the toggle doesn’t lose user configuration.
    public bool IsOnKeepVMAlive
    {
        get { return _instanceIdleTimeout!.Int32Value < 0; }
        set
        {
            Set(ref _instanceIdleTimeout!, value ? -1 : _defaultInstanceIdleTimeout, nameof(IsOnKeepVMAlive));
            OnPropertyChanged(nameof(InstanceIdleTimeout));
            OnPropertyChanged(nameof(InstanceIdleTimeoutEnabled));
            OnPropertyChanged(nameof(VMIdleTimeoutEnabled));
            InstanceIdleTimeout_ResetEnabled = !Equals(_defaultInstanceIdleTimeout, _instanceIdleTimeout!.Int32Value);
        }

src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs:180

  • Pending changes formatting will currently show negative idle timeouts as “-1 ms”. Since the service treats values < 0 as “never idle-terminate”, the apply dialog should format negative InstanceIdleTimeout/VMIdleTimeout as a user-friendly localized value (e.g. “Never”) instead of a negative duration.
                    case WslConfigEntry.InitialAutoProxyTimeout:
                    case WslConfigEntry.InstanceIdleTimeout:
                    case WslConfigEntry.VMIdleTimeout:
                        return string.Format("Settings_MillisecondsStringFormat".GetLocalized(), (int)value);
                    default:

Comment thread localization/strings/en-US/Resources.resw
Comment thread src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml

@benhillis benhillis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the mechanism checks out - _VmIsIdle() only returns true once no running instance has a valid client id, so pinning instanceIdleTimeout to a negative value does keep the VM up. A few things I hit while reading through it.

</ctControls:SettingsExpander.Items>
</ctControls:SettingsExpander>
<ctControls:SettingsExpander x:Name="InstanceIdleTimeoutExpander" x:Uid="Settings_InstanceIdleTimeout" IsEnabled="{x:Bind ViewModel.InstanceIdleTimeoutEnabled, Mode=OneWay}">
<TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.InstanceIdleTimeout, Mode=OneWay, Converter={StaticResource MillisecondsStringConverter}}"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the toggle is on, InstanceIdleTimeout is -1, and MillisecondsStringConverter only special-cases ulong 0, so this collapsed summary ends up reading literally -1 ms. Same thing shows up in the apply-changes dialog, since SettingsApplyHelper.FormatValue runs the new entry through Settings_MillisecondsStringFormat - so toggling Keep WSL VM alive produces a confirmation line like Distribution idle timeout: -1 ms for a field the user never touched.

Could we have the converter return null (or something like Never) for negative values, and map the toggle to Settings_KeepVMAlive/Header in the apply summary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer it showing -1 as it is clearly communicating what it's setting. I think changing it to show 'Never' while making it more readable, makes it less clear on what actual settings are changing.
So I'd prefer to stick with displaying it as -1 as that is what gets truly set in the file.

Comment thread src/windows/wslsettings/ViewModels/Settings/OptionalFeaturesViewModel.cs Outdated
Comment thread localization/strings/en-US/Resources.resw Outdated
Copilot AI review requested due to automatic review settings July 31, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs:179

  • InstanceIdleTimeout is formatted as milliseconds unconditionally. When the new "Keep WSL running" toggle sets this value to a negative number (e.g. -1), the Apply Changes dialog will display "-1 milliseconds", which is confusing for a user-facing setting that uses a sentinel value.

Consider special-casing negative InstanceIdleTimeout values to display a meaningful localized label (reusing the existing Keep WSL running header resource is one option) instead of formatting as milliseconds.

                    case WslConfigEntry.InitialAutoProxyTimeout:
                    case WslConfigEntry.InstanceIdleTimeout:
                    case WslConfigEntry.VMIdleTimeout:
                        return string.Format("Settings_MillisecondsStringFormat".GetLocalized(), (int)value);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants